﻿<table class="key-value highlight-key">
@{
    var attrs = Model as IEnumerable<dynamic>;
    if(attrs.Any())
    {
        var tmp = new List<dynamic>();
        foreach(var i in attrs.OrderBy(x => JDM.Int32(x.DisplayOrder)))
        {
            var t_attr = (i.Translations as IEnumerable<dynamic>)
                .SingleOrDefault(x => JDM.Int32(x.Language.EntityID) ==
                    JDM.Int32(Svc.Localization.Language.EntityID));
            tmp.Add(new
            {
                Entity = i,
                Name = t_attr != null ? JDM.String(t_attr.Name) : JDM.String(i.EntityID),
                Value = t_attr != null ? JDM.String(t_attr.Value) : JDM.String(i.EntityID),
            });
        }
        foreach(var g in tmp.GroupBy(x => x.Name))
        {
            <tr>
                <td>
                    <label>@g.Key</label>
                </td>
                <td>
                    <ul class="bar">
                    @{
                        var n = 0;
                        foreach(var i in g.OrderBy(x => x.Value))
                        {
                            <li>
                            @if(JDM.HasFlags(i.Entity.Flags, "AllowedForSearch"))
                            {
                                <a href="@Url.Action(Loc.Act("Index").Set(new
                                {
                                    attributeIDs = JDM.String(i.Entity.EntityID)
                                }).Localized())">@i.Value</a>
                            }
                            else
                            {
                                <span>@i.Value</span>
                            }
                            </li>
                            if(n < g.Count() - 1)
                            {
                                <li class="separator">,</li>
                            }
                            n++;
                        }
                    }
                    </ul>
                </td>
            </tr>
        }
    }
    else
    {
        <tr>
            <td class="empty"><span>@T(Res.In("Common").Of("Expr").Name("NoData"))</span></td>
        </tr>
    }
}
</table>
